$(function () {
    var querystring = window.location.search;
    var id = (querystring.match(/id=(\w*)/))[1];
    var nodeidx = (querystring.match(/node=(\w+)/))[1];
    var INFO = window.NODE[nodeidx];
    var path = "a/b/c/d";
    if (id == "") {
        $.auto.alert("错误", "发生系统错误，没有找到项目编号！");
        return;
    }
    $(".title_left").text(INFO.title);
    function closeMe() {
        window.parent.$('#topTabs').tabs('close', "详细信息");
    }
    $(window).resize(function () {
        $("#ttWrap").css({
            height: ($(window).innerHeight() - $("#ttWrap").offset().top - 10) + 'px',
            width: (($(window).innerWidth() - 30) + 'px')
        });
    }).resize();
    function renderPath() {
        path = _.trim(path, "/");
        var pList = path.split('/');
        var strPath = "", curPath = "";
        _.each(pList, function (p, i) {
            curPath += p + "/";
            if (i == pList.length - 1) {
                strPath += "<li class=\"active\">" + p + "</li>";
            }
            else {
                strPath += "<li><a href=\"" + curPath + "\">" + p + "</a></li>";
            }
        });
        $("#olPath").empty().append(strPath);
    }
    function getFolderInfo() {
        var list = [{ FILENAME: "xxxx", UPLOADTIME: "2016-3-7", TYPE: "DOC" }];
        $("#tt").autoTable({
            data: list,
            header: [[{ title: '序号', span: [] }, { title: '名称', span: [] },
                    { title: '上传日期', span: [] }, { title: '类型', span: [] }]],
            headerFields: ["FILENAME", "UPLOADTIME", "TYPE"],
            keydataOnRow: ["TYPE"],
            isRownumber: true,
            isPageable: false,
            isScrollable: true,
            isSelectable: true,
            selectMulti: false });
        renderPath();
    }
    ;
    getFolderInfo();
    function getDownloadfile(name) {
        var w = window.open('文件的项目地址' + name);
        $(w).on("load", function () {
            w.close();
        });
        return false;
    }
    $("#tt").on("click", ".tt_FILENAME a", function (event) {
        var name = $(this).text();
        var type = $(this).parent().data("type");
        if (type == "directory") {
            path += "${name}";
            getFolderInfo();
        }
        else {
            getDownloadfile(name);
        }
    });
    $('#fileupload').fileupload({
        dataType: 'json',
        done: function (e, data) {
            $.each(data.result.files, function (index, file) {
                $('<p/>').text(file.name).appendTo(document.body);
            });
        }
    });
});
